<template>
  <div class="app-container drawer-container">
    <div class="block">
      <div class="title">1. 填写巡检项信息</div>
      <el-form
        ref="formRef"
        :model="form"
        :inline="true"
        size="default"
        label-width="100"
        label-position="left"
        :rules="rules"
      >
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="巡检任务名称" prop="taskSetName">
              <el-input
                v-model="form.taskSetName"
                placeholder="请输入巡检任务名称"
                clearable
                maxlength="20"
                show-word-limit
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="巡检方向" prop="taskSetType">
              <el-radio-group
                v-model="form.taskSetType"
                @change="f_ChangeTaskSetType(true)"
              >
                <el-radio :value="2">按区域</el-radio>
                <el-radio :value="1">按线路</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="线路选择" prop="inspDestId">
              <el-select
                :placeholder="
                  form.taskSetType == 1 ? '请选择线路巡检' : '请选择区域巡检'
                "
                size="default"
                v-model="form.inspDestId"
                @change="f_ChangePolygon"
                placement="bottom"
              >
                <el-option
                  :label="item.inspLineName"
                  :value="item.inspLineId"
                  :key="item.inspLineId"
                  v-for="item in lineDataByTypeData"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="选择部门" prop="inspDepartmentId">
              <el-select
                placeholder="请选择部门"
                size="default"
                v-model="form.inspDepartmentId"
                @change="f_ChangeDep(true)"
              >
                <el-option
                  :label="item.name"
                  :value="item.id"
                  :key="item.id"
                  v-for="item in depData"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="选择巡检员" prop="inspUserId">
              <el-select
                placeholder="请选择巡检员"
                size="default"
                v-model="form.inspUserId"
              >
                <el-option
                  :label="
                    item.name.length > 20
                      ? item.name.substr(0, 20) + '...'
                      : item.name
                  "
                  :value="item.id"
                  :key="item.id"
                  v-for="item in operatorData"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="是否启用" prop="isEnabled">
              <el-radio-group v-model="form.isEnabled">
                <el-radio :value="true">是</el-radio>
                <el-radio :value="false">否</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="备注" prop="remark">
              <el-input
                v-model="form.remark"
                placeholder="请输入备注"
                clearable
                type="textarea"
                maxlength="50"
                show-word-limit
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div class="block" style="padding-bottom: 80px">
      <div class="title">
        2. 配置巡检点任务
        <el-button
          @click="f_OpenConfigTempDialog(null)"
          type="warning"
          class="float-right pl-[20px!important] pr-[20px!important] h-[22px!important] text-size-[12px] ml-[20px]"
        >
          <i-ep-SetUp
            class="mr-[2px] text-size-[11px] v-bottom mr-[4px]"
          />通用模板
        </el-button>

        <el-button
          @click="f_OpenConfigDialog(null, 10000)"
          type="primary"
          class="float-right pl-[20px!important] pr-[20px!important] h-[22px!important] text-size-[12px]"
        >
          <i-ep-SetUp
            class="mr-[2px] text-size-[11px] v-bottom mr-[4px]"
          />批量配置
        </el-button>

        <el-button
          v-if="form.taskSetType == 2 && form.inspDestId"
          @click="f_OpenSelectPointDialog()"
          type="primary"
          class="float-right pl-[20px!important] pr-[20px!important] h-[22px!important] text-size-[12px] mr-[20px]"
        >
          <i-ep-location
            class="mr-[2px] text-size-[11px] v-bottom mr-[4px]"
          />选择巡检点
        </el-button>
      </div>
      <el-table
        v-loading="loading"
        :data="form.details"
        border
        header-row-class-name="table-header"
        ref="tableRef"
      >
        <el-table-column type="selection" width="50" align="center" />
        <el-table-column type="index" label="序号" width="60" align="center" />
        <el-table-column label="管点名称" prop="pointName" align="center">
          <template #default="scope">
            <span v-if="!scope.row.isDel"
              >{{ scope.row.pointName }} ({{ scope.row.pointGisNo }})</span
            >
            <span v-if="scope.row.isDel" class="color-[red]">已删除</span>
          </template>
        </el-table-column>
        <el-table-column label="巡检管点类型" prop="className" align="center" />
        <el-table-column label="是否配置" align="center">
          <template #default="scope">
            <el-tag v-if="scope.row.inspContent.length" type="success"
              >已配置</el-tag
            >
            <el-tag v-else type="warning">未配置</el-tag>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" align="center" width="280">
          <template #default="scope">
            <el-button
              v-if="!scope.row.isDel"
              class="text-[12px]"
              type="primary"
              link
              @click="f_OpenConfigDialog(scope.row, scope.$index)"
              ><i-ep-edit
                class="font-[11px] mt-[-2px]"
              />配置巡检内容</el-button
            >
            <el-button
              v-if="!scope.row.isDel"
              type="primary"
              link
              class="font-[11px] mt-[-2px] text-[12px]"
              @click="f_OpenCopyDialog(scope.row, scope.$index)"
              ><i-ep-view />复制任务</el-button
            >
            <el-button
              @click="f_Del(scope.$index)"
              class="text-[12px]"
              type="danger"
              link
              ><i-ep-delete class="font-[11px] mt-[-2px]" />删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>

    <div class="footer pb-[15px] mt-[-20px] pr-[15px]">
      <el-button type="primary" @click="debounce_fun()">确 定</el-button>
      <el-button @click="f_CloseDialog(true)">取 消</el-button>
    </div>

    <!-- 配置巡检内容 弹框 -->
    <el-drawer
      v-model="dialogConfig.visible"
      title="3. 配置巡检内容"
      size="1300px"
      @close="f_CloseDialog(false)"
      destroy-on-close
    >
      <!-- <div
        v-if="currentIndex == 10000 && configTableData.length == 0"
        class="text-[red]"
      >
        当前未选择巡检点，默认配置全局
      </div> -->
      <config_dialog
        :insp-content="inspContent"
        @confirm="f_CloseConfigDialog"
        @close="f_CloseDialog(false)"
      />
    </el-drawer>

    <!-- 配置通用模板 弹框 -->
    <el-drawer
      v-model="dialogConfigTemp.visible"
      title="配置通用模板内容"
      size="1300px"
      @close="f_CloseDialog(false)"
      destroy-on-close
    >
      <config_dialog
        :insp-content="inspContent"
        @confirm="f_CloseConfigTempDialog"
        @close="f_CloseDialog(false)"
      />
    </el-drawer>

    <!-- 复制任务 弹框 -->
    <el-dialog
      v-model="dialogCopy.visible"
      title="复制任务到"
      width="500px"
      @close="f_CloseDialog(false)"
    >
      <div class="p-[15px]">
        <el-table
          v-loading="loading"
          :data="copyTableData"
          border
          header-row-class-name="table-header"
          ref="copyTableRef"
        >
          <el-table-column type="selection" width="50" align="center" />
          <el-table-column
            type="index"
            label="序号"
            width="50"
            align="center"
          />
          <el-table-column label="管点名称" prop="pointName" align="center" />
          <el-table-column label="是否配置" align="center">
            <template #default="scope">
              <el-tag v-if="scope.row.inspContent.length" type="success"
                >已配置</el-tag
              >
              <el-tag v-else type="warning">未配置</el-tag>
            </template>
          </el-table-column>
        </el-table>
      </div>

      <template #footer>
        <div class="dialog-footer pb-[15px] mt-[-20px] pr-[15px]">
          <el-button type="primary" @click="f_HandleSubmitCopy"
            >确 定</el-button
          >
          <el-button @click="f_CloseDialog(false)">取 消</el-button>
        </div>
      </template>
    </el-dialog>

    <!-- 选择巡检点 弹框 -->
    <el-dialog
      v-model="dialogSelectPoint.visible"
      title="选择巡检点"
      width="1200px"
      @close="f_CloseDialog(false)"
    >
      <div class="p-[15px]">
        <el-form
          ref="formRef"
          :model="form"
          :inline="true"
          size="default"
          label-width="100"
          label-position="left"
          :rules="rules"
        >
          <el-row :gutter="20">
            <el-col :span="8">
              <el-form-item label="筛选区域" prop="polygonId">
                <el-select
                  placeholder="请选择线路"
                  size="default"
                  v-model="searchForm.polygonId"
                  @change="f_GetPoint"
                  placement="bottom"
                  clearable
                >
                  <el-option
                    :label="item.polygonName"
                    :value="item.polygonId"
                    :key="item.polygonId"
                    v-for="item in polygonData"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="巡检点类型" prop="pointId">
                <el-select
                  placeholder="请选择"
                  size="default"
                  v-model="searchForm.className"
                  clearable
                  @change="f_GetPoint"
                  multiple
                  collapse-tags
                >
                  <el-option
                    :label="item.polygonName"
                    :value="item.className"
                    :key="item.classId"
                    v-for="item in pointTypeData"
                  />
                </el-select>
              </el-form-item>
            </el-col>

            <el-col :span="8" style="text-align: right">
              <el-button type="primary" @click="f_ConfirmSelectPoint"
                >确 定</el-button
              >
              <el-button @click="f_CloseSelectPointDialog">取 消</el-button>
            </el-col>
          </el-row>
        </el-form>
        <el-table
          v-loading="loading"
          :data="searchPointData"
          border
          header-row-class-name="table-header"
          height="500px"
          ref="searchTableRef"
        >
          <el-table-column type="selection" width="50" align="center" />
          <el-table-column
            type="index"
            label="序号"
            width="70"
            align="center"
          />
          <el-table-column label="管点名称" prop="pointName" align="center" />
          <el-table-column label="GIS编号" prop="pointGisNo" align="center" />
          <el-table-column label="管点类型" prop="className" align="center" />
          <el-table-column label="详细地址" prop="address" align="center">
            <template #default="scope">
              {{ scope.row.address }}
              <img
                :src="remarkImg"
                style="height: 16px; vertical-align: middle"
              />
            </template>
          </el-table-column>
        </el-table>
      </div>
    </el-dialog>
  </div>
</template>

<script setup lang="ts">
defineOptions({
  name: "DictData",
  inheritAttrs: false,
});
import { debounce } from "lodash";
const emits = defineEmits(["close"]);
import DeviceCategoryApi from "@/api/DeviceCategoryApi";
import { find, uniqBy, uniq } from "lodash";
import TaskSetAPI from "@/api/TaskSetAPI";
import config_dialog from "./config.vue";
import GisPointInfoAPI from "@/api/GisPointInfoAPI";
// const props = defineProps(["depData", "polygonData", "form"]);
const searchTableRef = ref();
const copyTableRef = ref();
const props = defineProps({
  depData: {
    type: Array,
    default: () => {
      return [];
    },
  },
  lineData: {
    type: Array,
    default: () => {
      return [];
    },
  },
  polygonData: {
    type: Array,
    default: () => {
      return [];
    },
  },
  pointData: {
    type: Array,
    default: () => {
      return [];
    },
  },
  form: {
    type: Array,
    default: () => {
      return {};
    },
  },
});

const remarkImg = ref(
  new URL(`../../../assets/device/point-1.png`, import.meta.url).href
);

const tableRef = ref();
const configTableData = ref([]);
const copyTableData = ref([]);
const depData = reactive(props.depData);
const polygonData = reactive(props.polygonData);
let form = reactive(props.form);
let operatorData = ref([]);
const lineData = reactive(props.lineData);
const pointData = reactive(props.pointData);
const searchPointData = ref([]);
const oldSearchPointData = ref([]);
const selectPolygonData = ref([]);
const selectPointTypeData = ref([]);
const inspContent = ref([]);
const currentIndex = ref(0);
const lineDataByTypeData = ref([]);
const dialogCopy = reactive({
  visible: false,
  title: "",
});
const dialogConfig = reactive({
  visible: false,
  title: "",
});

const dialogConfigTemp = reactive({
  visible: false,
  title: "",
});
const dialogSelectPoint = reactive({
  visible: false,
  title: "",
});

// 放抖
const debounce_fun = debounce(f_HandleSubmit, 1000);

// 管点类型
const pointTypeData = ref([]);
const formRef = ref(ElForm);
const dataFormRef = ref(ElForm);
const loading = ref(false);
const rules = reactive({
  taskSetName: [
    { required: true, message: "请输入巡检任务名称", trigger: "blur" },
  ],
  inspDepartmentId: [
    { required: true, message: "请选择部门", trigger: "change" },
  ],
  inspUserId: [{ required: true, message: "请选择巡检员", trigger: "change" }],
  taskSetType: [{ required: true, message: "请选择巡检员", trigger: "change" }],
  inspDestId: [
    { required: true, message: "请选择线路区域", trigger: "change" },
  ],
});

const searchForm = reactive({
  polygonId: undefined,
  className: [],
});

// 返回赛选之后的管点
function f_GetPoint() {
  let data1 = [];
  let data2 = [];
  if (searchForm.className.length > 0 && searchForm.polygonId) {
    oldSearchPointData.value.forEach((item) => {
      if (searchForm.className.includes(item.className)) {
        data1.push(item);
      }
    });

    data1.forEach((item) => {
      if (item.polygonId == searchForm.polygonId) {
        data2.push(item);
      }
    });
    searchPointData.value = data2;
  }

  if (searchForm.className.length && !searchForm.polygonId) {
    oldSearchPointData.value.forEach((item) => {
      if (searchForm.className.includes(item.className)) {
        data1.push(item);
      }
    });
    searchPointData.value = data1;
  }

  if (!searchForm.className.length && searchForm.polygonId) {
    oldSearchPointData.value.forEach((item) => {
      if (item.polygonId == searchForm.polygonId) {
        data1.push(item);
      }
    });
    searchPointData.value = data1;
  }

  if (!searchForm.className.length && !searchForm.polygonId) {
    searchPointData.value = oldSearchPointData.value;
  }
}

// 删除 管点
function f_Del(index: number) {
  ElMessageBox.confirm("确认是否删除?", "警告", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  }).then(() => {
    form.details.splice(index, 1);
  });
}

// 关闭 配置 弹框
function f_CloseConfigDialog(data) {
  // if (currentIndex.value == 10000 && configTableData.value.length == 0) {
  //   form.details.forEach((item, index) => {
  //     form.details[index].inspContent = data;
  //   });
  if (currentIndex.value == 10000 && configTableData.value.length > 0) {
    let selectDataId = [];
    configTableData.value.forEach((item) => {
      selectDataId.push(item.pointId);
    });
    form.details.forEach((item, index) => {
      if (selectDataId.includes(item.pointId)) {
        form.details[index].inspContent = data;
      }
    });
  } else {
    form.details[currentIndex.value].inspContent = data;
  }

  dialogConfig.visible = false;
}

// 关闭 配置 弹框
function f_CloseConfigTempDialog(data) {
  form.inspTempContent = data;
  dialogConfigTemp.visible = false;
}

// 部门 change
function f_ChangeDep(type) {
  let params = {
    DepartmentId: form.inspDepartmentId,
  };
  if (type) {
    form.inspUserId = undefined;
  }
  TaskSetAPI.api_query_operators(params).then(({ data, succeeded }) => {
    if (succeeded) {
      operatorData.value = data;
    }
  });
}

// 详情
function f_QueryDetail() {
  TaskSetAPI.api_detail(form.taskSetId).then(({ data, succeeded }) => {
    if (succeeded) {
      form.details = data;
      if (form.details.length) {
        form.details.forEach((item, index) => {
          let tempPointData = find(pointData, { pointId: item.pointId });
          if (tempPointData) {
            form.details[index].pointName = tempPointData.pointName;
          } else {
            form.details[index].pointName = item.point.pointName;
          }
          form.details[index].isDel = item.point.isDel;
          form.details[index].className = item.point.className;
          form.details[index].pointGisNo = item.point.pointGisNo;
        });
      }
    }
  });
}

// 巡检方向 change
function f_ChangeTaskSetType(flag) {
  lineDataByTypeData.value = [];
  if (flag) {
    form.inspDestId = undefined;
  }
  form.details = [];

  lineData.forEach((item) => {
    if (item.inspLineType == form.taskSetType) {
      lineDataByTypeData.value.push(item);
    }
  });

  if (form.taskSetId && form.taskSetType == 2 && !flag) {
    selectPolygonData.value = [];
    selectPointTypeData.value = [];
    let polygonId = [];
    let jsonPolygonData = find(lineDataByTypeData.value, {
      inspLineId: form.inspDestId,
    });
    if (jsonPolygonData) {
      polygonId.push(jsonPolygonData.startPositionId);
      polygonId.push(jsonPolygonData.endPositionId);
      if (jsonPolygonData.byWay && jsonPolygonData.byWay.length) {
        jsonPolygonData.byWay.forEach((item) => {
          polygonId.push(item.value);
        });
      }
      polygonId.push(jsonPolygonData.endPositionId);
    } else {
      return;
    }

    searchPointData.value = [];
    oldSearchPointData.value = [];

    polygonId.forEach((item) => {
      let coordinatesData = find(polygonData, {
        polygonId: item,
      });

      if (coordinatesData) {
        selectPolygonData.value.push(item);
        let coordinates = JSON.parse(coordinatesData.jsonGeom).coordinates[0];
        f_GetPointByCoordinate(coordinates, item);
      }
    });
  }
}

// 根据区域的坐标 获取内部管点数据
function f_GetPointByCoordinate(jsonPolygon, polygonId) {
  let params = {
    pageSize: 100,
    pageIndex: 1,
    jsonPolygon: JSON.stringify(jsonPolygon),
  };
  GisPointInfoAPI.api_query_point_by_polygon(params).then(
    ({ data, succeeded }) => {
      if (succeeded) {
        data.items.forEach((item, index) => {
          searchPointData.value.push({
            polygonId: polygonId,
            pointId: item.pointId,
            inspContent: [],
            inspSort: index,
            pointName: item.pointName,
            pointGisNo: item.pointGisNo,
            address: item.address,
            className: item.className,
            point: item,
          });
          oldSearchPointData.value.push({
            polygonId: polygonId,
            pointId: item.pointId,
            inspContent: [],
            inspSort: index,
            pointName: item.pointName,
            pointGisNo: item.pointGisNo,
            address: item.address,
            className: item.className,
            point: item,
          });
          selectPointTypeData.value = uniqBy(
            oldSearchPointData.value,
            "classId"
          );
        });
      }
    }
  );
}

// 打开巡检点选择
function f_OpenSelectPointDialog() {
  searchForm.className = [];
  searchForm.polygonId = undefined;
  dialogSelectPoint.visible = true;

  setTimeout(() => {
    searchTableRef.value.toggleAllSelection();
  }, 200);
}

// 关闭巡检点选择
function f_CloseSelectPointDialog() {
  dialogSelectPoint.visible = false;
}

// 确认选择巡检点
function f_ConfirmSelectPoint() {
  let selectPoint = searchTableRef.value.getSelectionRows();
  if (!selectPoint.length) {
    ElMessage.error("请选择巡检点！");
    return;
  }
  // 判断是否存在重复添加点的情况
  let pointIds = [];
  selectPoint.forEach((item) => {
    pointIds.push(item.pointId);
  });
  form.details.forEach((item) => {
    pointIds.push(item.pointId);
  });
  let totalNum = JSON.parse(JSON.stringify(pointIds)).length;
  let num = uniq(pointIds).length;
  if (totalNum != num) {
    ElMessage.error("巡检点重复添加！");
    return;
  }
  selectPoint.forEach((item) => {
    form.details.push(item);
  });
  f_CloseSelectPointDialog();
}

// 区域 change
function f_ChangePolygon() {
  selectPolygonData.value = [];
  selectPointTypeData.value = [];
  let polygonId = [];
  let jsonPolygonData = find(lineDataByTypeData.value, {
    inspLineId: form.inspDestId,
  });
  if (jsonPolygonData) {
    polygonId.push(jsonPolygonData.startPositionId);

    if (jsonPolygonData.byWay && jsonPolygonData.byWay.length) {
      jsonPolygonData.byWay.forEach((item) => {
        polygonId.push(item.value);
      });
    }
    polygonId.push(jsonPolygonData.endPositionId);
  } else {
    return;
  }
  form.details = [];
  searchPointData.value = [];
  oldSearchPointData.value = [];
  if (form.taskSetType == 2) {
    polygonId.forEach((item) => {
      let coordinatesData = find(polygonData, {
        polygonId: item,
      });
      selectPolygonData.value.push(item);
      let coordinates = JSON.parse(coordinatesData.jsonGeom).coordinates[0];
      f_GetPointByCoordinate(coordinates, item);
    });
  } else {
    polygonId.forEach((item, index) => {
      let pointValue = find(pointData, { pointId: item });
      console.log(pointValue);
      if (pointValue) {
        form.details.push({
          pointId: pointValue.pointId,
          inspContent: [],
          inspSort: index,
          pointName: pointValue.pointName,
          className: pointValue.className,
          pointGisNo: pointValue.pointGisNo,
          point: pointValue,
        });
      }
    });
  }
}

// 配置内容 弹框
function f_OpenConfigDialog(data: any, index: number) {
  configTableData.value = tableRef.value.getSelectionRows();
  currentIndex.value = index;
  if (!configTableData.value.length && index == 10000) {
    ElMessage.error("请现勾选需要配置的管点!");
    return;
  }

  // configTableData.value = [];
  if (data) {
    inspContent.value = JSON.parse(JSON.stringify(data.inspContent));
  } else {
    inspContent.value = [];
    // configTableData.value = tableRef.value.getSelectionRows();
  }
  dialogConfig.visible = true;
}

// 配置内容 弹框
function f_OpenConfigTempDialog(data: any) {
  inspContent.value = form.inspTempContent;
  dialogConfigTemp.visible = true;
}

// 配置复制 弹框
function f_OpenCopyDialog(data: any, index) {
  if (!data.inspContent.length) {
    ElMessage.error("当前管点未配置巡检内容，无法复制！");
    return;
  }
  if (form.details.length == 1) {
    ElMessage.error("仅存在一个管点，无法复制！");
    return;
  }
  inspContent.value = data.inspContent;
  let arr = JSON.parse(JSON.stringify(form.details));
  arr.splice(index, 1);
  copyTableData.value = arr;
  dialogCopy.visible = true;
}

// 配置复制 确认
function f_HandleSubmitCopy() {
  let selectData = copyTableRef.value.getSelectionRows();
  console.log(selectData);
  if (!selectData.length) {
    ElMessage.error("请勾选需要配置的任务！");
    return;
  }
  let pointIds = [];
  selectData.forEach((item) => {
    pointIds.push(item.pointId);
  });
  form.details.forEach((item, index) => {
    if (pointIds.includes(item.pointId)) {
      form.details[index].inspContent = inspContent.value;
    }
  });
  dialogCopy.visible = false;
}

/** 字典表单提交 */
function f_HandleSubmit() {
  formRef.value.validate((isValid: boolean) => {
    if (isValid) {
      if (!form.taskSetName) {
        ElMessage.error("请填写巡检任务名称！");
        return;
      }
      if (!form.inspDestId) {
        ElMessage.error("请选择巡检线路！");
        return;
      }
      if (!form.inspDepartmentId) {
        ElMessage.error("请选择部门！");
        return;
      }
      if (!form.inspUserId) {
        ElMessage.error("请选择巡检员！");
        return;
      }

      let isAllConfigTmp = true;
      form.details.forEach((item) => {
        if (item.inspContent.length == 0) {
          isAllConfigTmp = false;
        }
      });
      if (!form.inspTempContent.length && !isAllConfigTmp) {
        ElMessage.error("请配置巡检点内容");
        return;
      }

      let obj = Object.assign({}, form);

      let inspDeppartmentName = find(depData, {
        id: obj.inspDepartmentId,
      }).name;
      let inspDestName = find(lineData, {
        inspLineId: obj.inspDestId,
      }).inspLineName;
      let inspUserName = find(operatorData.value, {
        id: obj.inspUserId,
      }).name;

      obj.details.forEach((item, index) => {
        // obj.details[index].inspContent = JSON.stringify(item.inspContent);
        obj.details[index].inspSort = index;
        delete obj.details[index].pointName;
      });

      obj.inspDestName = inspDestName;
      obj.inspUserName = inspUserName;
      obj.inspDeppartmentName = inspDeppartmentName;

      loading.value = false;
      TaskSetAPI.api_add(obj).then(({ data, errors, succeeded }) => {
        if (succeeded) {
          ElMessage.success("提交成功！");
          f_CloseDialog(true);
        } else {
          ElMessage.error(errors);
        }
        loading.value = false;
      });
    }
  });
}

// 关闭弹窗
function f_CloseDialog(type) {
  dialogCopy.visible = false;
  dialogConfig.visible = false;
  dialogSelectPoint.visible = false;
  dialogConfigTemp.visible = false;
  if (type) {
    emits("close");
  }
}

// 查询管点类型
function f_HandelQueryPointType() {
  const params1 = {
    pageSize: 100,
    pageIndex: 1,
    pClassId: "01",
  };
  DeviceCategoryApi.api_query_point(params1).then(
    ({ data, errors, succeeded }) => {
      if (succeeded) {
        pointTypeData.value = data;
      }
    }
  );
}

onMounted(() => {
  console.log(form);
  if (form.taskSetId) {
    f_QueryDetail();
    f_ChangeDep(false);
  }
  f_ChangeTaskSetType(false);
  f_HandelQueryPointType();
});
</script>
<style lang="scss" scoped>
.drawer-container {
  background: transparent;

  .block {
    padding: 15px;
    margin-bottom: 20px;
    background: #fff;

    .title {
      padding-bottom: 10px;
      margin-bottom: 20px;
      font-size: 14px;
      font-weight: bold;
      border-bottom: 1px dashed #eee;
    }

    :deep .el-form {
      .el-form-item {
        width: 100%;

        .el-form-item__label {
          font-size: 12px !important;
        }
      }
    }
  }
}

.footer {
  position: absolute;
  bottom: 0;
  left: 0;
  z-index: 1000;
  width: 100%;
  padding: 15px;
  text-align: center;
  background: #fff;
  border-top: 1px dashed #eee;

  button {
    width: 160px !important;
    height: 28px !important;
    margin-right: 40px;
    margin-left: 40px;
    border-radius: 15px;

    > span > svg {
      margin-right: 6px;
    }
  }
}

:deep .el-form--inline .el-form-item {
  width: 100%;
}
</style>
